import http from './config';
import baseUrl from './baseUrl';

interface ServiceParams {
    [key: string]: any;
}

interface ServiceExtra {
    [key: string]: any;
}

interface ApiService {
    testGet: (params?: ServiceParams) => Promise<any>;
    testPost: (params?: ServiceParams) => Promise<any>;
    getData: (params?: ServiceParams, extra?: ServiceExtra) => Promise<any>;
    testPostForm: (params?: ServiceParams) => Promise<any>;
    testPut: (params?: ServiceParams) => Promise<any>;
    testPutForm: (params?: ServiceParams) => Promise<any>;
    testDelete: (params?: ServiceParams) => Promise<any>;
    GetDownload: (params?: ServiceParams) => Promise<any>;
    testRequest: (params?: ServiceParams) => Promise<any>;
    testRequest1: (params?: ServiceParams) => Promise<any>;
    testRequest2: (params?: ServiceParams) => Promise<any>;
}

export const service: ApiService = {
    testGet: (params: ServiceParams = {}) => {
        return http.get(baseUrl + '/article/download/blob', params);
    },
    testPost: (params: ServiceParams = {}) => {
        return http.post(baseUrl + '/article', params, {
            responseType: 'json'
        });
    },
    // params 参数，extra额外配置
    getData: (params: ServiceParams = {}, extra: ServiceExtra = {}) => {
        return http.get(baseUrl.testUrl + '/article', params, {
            responseType: 'json',
            cancel: true,
            ...extra
        });
    },
    testPostForm: (params: ServiceParams = {}) => {
        return http.postForm(baseUrl.testUrl + '/article', params, {
            cancel: true,
            key: 'cang'
        });
    },
    testPut: (params: ServiceParams = {}) => {
        return http.put(baseUrl.testUrl + '/article', params);
    },
    testPutForm: (params: ServiceParams = {}) => {
        return http.putForm(baseUrl.testUrl + '/article', params);
    },
    testDelete: (params: ServiceParams = {}) => {
        return http.delete(baseUrl.testUrl + '/article', params);
    },
    GetDownload: (params: ServiceParams = {}) => {
        return http.GetDownload(baseUrl.testUrl + '/article/download/blob', params);
    },
    testRequest: (params: ServiceParams = {}) => {
        return http.get(baseUrl.testUrl + '/twp-server/warn/list', params, {
            // cancel: true,
            key: 'cang'
        });
    },
    testRequest1: (params: ServiceParams = {}) => {
        return http.get(baseUrl.testUrl + '/twp-server/population/listPoint', params, {
            headers: {
                Accesstoken: 'MTcyNDI5MDEzMDkxNV9qeF9hZG1pbg=='
            },
            cancel: true,
            key: 'ccc'
        });
    },
    testRequest2: (params: ServiceParams = {}) => {
        return http.get(baseUrl.testUrl + '/twp-server/population/listPoint', params, {
            headers: {
                Accesstoken: 'MTcyNDI5MDEzMDkxNV9qeF9hZG1pbg=='
            }
        });
    }
}; 